<template>
  <van-pull-refresh class="list" v-model="refreshing" @refresh="onLoad">
    <van-list
      v-model="loading"
      :finished="finished"
      @load="onNext"
      loading-text="加载中..."
      finished-text="没有更多了"
    >
      <slot :dataList="dataList"></slot>
    </van-list>
  </van-pull-refresh>
</template>
<script>
export default {
  data() {
    return {
      refreshing: false,
      loading: false,
      finished: false,
      page: 0,
      size: 10,
      dataList: []
    };
  },
  computed: {},
  props: {
    api: {},
    search: {}
  },
  watch: {},
  methods: {
    async onLoad() {
      this.refreshing = true;
      this.dataList = await this.load(false);
      this.refreshing = false;
    },
    async onNext() {
      this.dataList = this.dataList.concat(await this.load(true));
      this.loading = false;
    },
    async load(isNext) {
      this.page = isNext ? this.page + 1 : 0;
      return await this.api({
        ...this.search,
        page: this.page,
        size: this.size
      });
    }
  },
  components: {},
  mounted() {}
};
</script>
<style lang="less">
.list {
  height: 100%;
  .van-list {
    height: 100%;
  }
}
</style>